package com.hqyj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqyj.dao.EmployeeInformationMapper;
import com.hqyj.pojo.EmployeeContract;
import com.hqyj.pojo.EmployeeFile;
import com.hqyj.dao.EmployeeFileMapper;
import com.hqyj.pojo.EmployeeInformation;
import com.hqyj.service.IEmployeeFileService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author rock
 * @since 2021-10-20
 */
@Service
public class EmployeeFileServiceImpl extends ServiceImpl<EmployeeFileMapper, EmployeeFile> implements IEmployeeFileService {
    //注入mapper
    @Autowired(required = false)
    EmployeeFileMapper employeeFileMapper;
    @Override
    public HashMap<String, Object> select(EmployeeFile e) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        //定义分页对象
        Page<EmployeeFile> page = new Page<>(e.getPage(),e.getRow());
        //条件构造器
        QueryWrapper<EmployeeFile> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(e.getFileId()!=null,"file_id",e.getFileId());
        queryWrapper.like(e.getFileName()!=null&&!e.getFileName().equals(""),"file_name",e.getFileName());
        //查询数据库
        Page<EmployeeFile> eList =employeeFileMapper.selectPage(page,queryWrapper);
        //当前页集合
        map.put("list",eList.getRecords());
        //总页数
        map.put("totalPage",eList.getPages());
        //总条数
        map.put("total",eList.getTotal());
        //当前页
        map.put("curPage",e.getPage());
        if(e.getPage()==1){
            //上一页
            map.put("prePage",1);

        }else{
            map.put("prePage",e.getPage()-1);

        }
        if(e.getPage()==eList.getPages()){
            //下一页
            map.put("nextPage",eList.getPages());

        }else{
            map.put("nextPage",e.getPage()+1);

        }
        //每页显示条数
        map.put("row",e.getRow());

        return map;
    }

    @Override
    public HashMap<String, Object> add(EmployeeFile e) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        //新增
        int num = employeeFileMapper.insert(e);
        if(num>0){
            map.put("info","保存成功");
        }else{
            map.put("info","保存错误");
        }
        return map;

    }

    @Override
    public HashMap<String, Object> update(EmployeeFile e) {
        HashMap<String, Object> map = new HashMap<String, Object>();

        //修改
        int num = employeeFileMapper.updateById(e);
        if(num>0){
            map.put("info","保存成功");
        }else{
            map.put("info","保存错误");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> del(Integer e) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        //删除
        int num = employeeFileMapper.deleteById(e);
        if(num>0){
            map.put("info","保存成功");
        }else{
            map.put("info","保存错误");
        }
        return map;
    }

    @Override
    public List<EmployeeFile> selectAll(EmployeeFile e) {
        List<EmployeeFile> list = employeeFileMapper.selectAll();

        return list;
    }
}
